package com.wzc.hc.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzc.hc.entity.po.User;
import com.wzc.hc.entity.req.LoginReq;
import com.wzc.hc.mapper.UserMapper;
import com.wzc.hc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author m1825
 * @description 针对表【user】的数据库操作Service实现
 * @createDate 2025-03-03 14:32:40
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(LoginReq login) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", login.getUsername());
        wrapper.eq("user_password", login.getPassword());
        User user = userMapper.selectOne(wrapper);
        if (user == null)
            return "用户名或密码错误！";
        StpUtil.login(user.getId());
        return "登陆成功。";
    }
}




